<?php

namespace app\api\controller;

use fast\Http;
use think\Cache;
use think\Db;

/**
 * 
 * Class
 * @package app\api\controller
 */
class Tests
{

	use \app\common\traits\ToolTrait;


	public function twx()
	{

		$re = \app\api\controller\resigter\Bases::instance()->_avatar("opFhH6lakZrBPLz4o1B1evlSLoyg");
		dump($re);

		// $wechat = config("wechat");
		// if (request()->param("code")) {
		// 	$code = request()->param('code');
		// 	if ($code) {
		// 		$token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $wechat["AppID"] . '&secret=' . $wechat["AppSecret"] . '&code=' . $code . '&grant_type=authorization_code';
		// 		$token = json_decode(file_get_contents($token_url));
		// 		$opendid = $token->openid;
		// 		$access_token = $token->access_token;

		// 		// 获取用户信息

		// 		$info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $access_token . '&openid=' . $opendid . '⟨=zh_CN';
		// 		$info = json_decode(file_get_contents($info_url));
		// 		$data['name'] = $info->nickname;
		// 		$data['image'] = $info->headimgurl;
		// 		dump($info);
		// 	}
		// } else {
		// 	$redirect_uri = "http://community-system.fdkj.top/" . request()->pathinfo();
		// 	$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $wechat["AppID"] . "&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
		// 	Header("Location: " . $url); //请求
		// 	exit();
		// }



		// $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $wechat["AppID"] . "&secret=" . $wechat["AppSecret"];
		// $output = $this->https_request($url);
		// $returnData =  json_decode($output, true);  
		// dump($returnData);
		// $access_token = $returnData["access_token"];

		// $openid = "opFhH6i4BFItpaZe70rtv89uee1o";


		// // $urls = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $access_token . "&openid=" . $openid . "&lang=zh_CN";
		// $urls = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $openid . "&lang=zh_CN";
		// $token_data = $this->https_request($urls);
		// $ret = json_decode($token_data,true);
		// dump($ret);

	}



	/** 
	 * 数据请求 
	 * @return string $output 返回的数据，未解码 
	 */
	protected function https_request($url, $data = null)
	{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
		if (!empty($data)) {
			curl_setopt($curl, CURLOPT_POST, 1);
			curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
		}
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return $output;
	}

	public function tes()
	{
		$image = $_SERVER['DOCUMENT_ROOT'] . "/uploads/qrcode/89c71f0f9fbc0adc6d8d1dc139230046.png";


		$om = pathinfo($image);
		dump($om);

		$this->gaussian_blur($image);
	}

	public function gaussian_blur($srcImg, $radius = 10, $sigma = 10)
	{
		$image = imagecreatefrompng($srcImg);
		dump($image);
		// imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR, $radius);
		// imagepng($image, $srcImg, $sigma);
		// imagedestroy($image);
	}


	public function tce($time = '')
	{
		\app\common\controller\Caches::instance()->selectPlace("user");
	}

	public function tsq()
	{
		$fields = ["nums", "status"];

		$setFieldTpys = [
			"nums" 	=> "int(11)",
			"status"	=> "tinyint(1)",
		];
		$setFieldDefaultVals = [
			"nums" 	=> "0",
			"status"	=> "1",
		];

		$setFieldComment = [
			"nums" 	=> "增长数",
			"status"	=> "状态:1=参与,2=达标",
		];
		$obj = new \app\common\controller\Sqls("activity_take_nums");

		$obj->setFieldTpys 		  	= $setFieldTpys;
		$obj->setFieldDefaultVals 	= $setFieldDefaultVals;
		$obj->setFieldComment 		= $setFieldComment;

		$obj->createTable($fields, "新人礼活动增长随机数");
	}

	public function tac()
	{
		$sn = '68866010012348';
		$money = 100000;
		// $time = '1711243849';
		$time = '1711419477';
		// $time = '1719195477';
		\app\data\controller\Activity::instance()->newlyTakes($sn, $money, $time);
	}

	public function tbca()
	{
		$file = "./timer/wx_img_bc.txt";
		if (!file_exists($file)) {
			file_put_contents($file, 1);
		}
		$page = file_get_contents($file);
		$limit = 100;
		$offset = ($page - 1) * $limit;
		$ret = Db::table("fd_user_xuni_wx_img")->limit((int)$offset, (int)$limit)->select();
		if ($ret) {
			$page = $page + 1;
			file_put_contents($file, $page);
			foreach ($ret as $vals) {
				$temp = [];
				$other = Db::table("fd_wx_head_img")->where('openid', $vals["openid"])->value("other");
				if ($other) {
					$decode = json_decode($other, true);
					$temp["country"] = $decode["country"];
					$temp["province"] = $decode["province"];
					$temp["city"] = $decode["city"];
					$temp["other"] = $other;
					Db::table("fd_user_xuni_wx_img")->where("id", $vals["id"])->update($temp);
				}
			}
		}
	}

	public function ttd()
	{
		try {
			$file = "./timer/wx_img.txt";
			if (!file_exists($file)) {
				file_put_contents($file, 1557);
			}
			$page = file_get_contents($file);
			$limit = 20;
			$offset = ($page - 1) * $limit;
			$ret = Db::table("fd_user_xuni_wxinfo")->order("id desc")->limit((int)$offset, (int)$limit)->select();

			if ($ret) {
				$page = $page + 1;
				file_put_contents($file, $page);
				foreach ($ret as $v) {
					$headers = @get_headers($v["headimg"]);
					if (count($headers) == 20) {
						unset($v['id']);
						$resource = Http::get($v["headimg"]);
						$path = "./uploads/takes/";
						$this->creDirectory($path);
						$file = $path . date("dMYHis") . rand(100, 999) . ".png";
						file_put_contents($file, $resource);

						$v["headimg"] = substr($file, 1);
						Db::table("fd_user_xuni_wx_img")->insert($v);

						// $file = file_get_contents($v["headimg"]);
						// $filend = "png"; //pathinfo($url, PATHINFO_EXTENSION);
						// file_put_contents('./uploads/' . time() . "." . $filend, $file);
					}
				}
			} else {
				throw new \Exception("没数据咯！！！！");
			}
		} catch (\Exception $e) {
			echo $e->getMessage();
		}
	}

	public function aa($url)
	{
		$filename = date("dMYHis") . '.jpg'; //文件名称生成
		ob_start(); //打开输出
		readfile($url); //输出图片文件
		$img = ob_get_contents(); //得到浏览器输出
		ob_end_clean(); //清除输出并关闭
		$size = strlen($img); //得到图片大小
		$fp2 = @fopen($filename, "a");
		fwrite($fp2, $img); //向当前目录写入图片文件，并重新命名
		fclose($fp2);
	}


	public function ttt()
	{
		\app\common\controller\Refunds::instance()->handle("CSSE09019820191");
	}

	public function ts()
	{

		$option = [
			"uid"		=> 22,
			"isChg" 	=> 2,
			"remark" 	=> "测试接口-减",
			"chgAmt" 	=> 37.5,
			"typs"		=> 'ESC',
		];
		$t =	\app\common\controller\Balance::instance()->changeOpera($option);
		dump($t);
	}

	public function tta()
	{
		echo 1;
		\app\data\controller\Apply::instance()->place_update_status(35, 7);
	}

	public function ttc()
	{
		\app\data\controller\Binds::instance()->customer_active('CSSE09019820191');
		\app\data\controller\Binds::instance()->customer_lost(35);
	}
	public function tts()
	{
		\app\data\controller\Trans::instance()->customer_month('CSSE09019820191', 10000, 1710140015);
		// \app\data\controller\Trans::instance()->active_stands_trans_store('CSSE09019820191', 1709966256, 1000);
	}

	public function phoneSave()
	{
		$phone = "18748149147";
		$poolKey = "FC100000177746880";
		$res = Aliyuns::phoneSave($phone, $poolKey);
		return json($res);
	}
}
